home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / sortobj.e < prev    next >
Text File  |  1995-02-11  |  3KB  |  83 lines

  1. -> sortobj.e: An abstract data manipulation class for Amiga E
  2. -> It's written by Trey Van Riper of the Cheese Olfactory Workshop.
  3. OPT MODULE
  4.  
  5. -> This is a totally abstract object to handle comparable objects.
  6.  
  7. EXPORT OBJECT sortobj
  8. ENDOBJECT
  9.  
  10. -> new() is the constructor.  You shouldn't have to create one.  Just make an
  11. -> 'init()' and 'opts()' procedure (if you need them) and use NEW obj.new()
  12. -> whenever you need to instantiate an object.
  13.  
  14. EXPORT PROC new(opts=0) OF sortobj
  15.  self.init()
  16.  self.opts(opts)
  17. ENDPROC
  18.  
  19. -> opts() could be useful <grin>.  Allows you to handle various options while
  20. -> invoking 'new()'... such as, perhaps, starting values.
  21.  
  22. EXPORT PROC opts(opts) OF sortobj IS EMPTY
  23.  
  24. -> init() sets up starting values for the object.
  25.  
  26. PROC init() OF sortobj IS EMPTY
  27.  
  28. -> The following seven functions are comparitive functions for deciding
  29. -> what is greater than, less than, or equal to what.  You'll note that
  30. -> to make all of these work, one only needs to define 'cmp()' in one's
  31. -> own derived object... the rest of these will auto-magically work!
  32.  
  33. -> lt() means 'less than'.
  34.  
  35. EXPORT PROC lt(item:PTR TO sortobj) OF sortobj IS IF self.cmp(item)<0 THEN TRUE ELSE FALSE
  36.  
  37. -> gt() means 'greater than'.
  38.  
  39. EXPORT PROC gt(item:PTR TO sortobj) OF sortobj IS IF self.cmp(item)>0 THEN TRUE ELSE FALSE
  40.  
  41. -> et() means 'equal to'.
  42.  
  43. EXPORT PROC et(item:PTR TO sortobj) OF sortobj IS IF self.cmp(item)=0 THEN TRUE ELSE FALSE
  44.  
  45. -> le() means 'Less than/Equal to'.
  46.  
  47. EXPORT PROC le(item:PTR TO sortobj) OF sortobj IS IF self.lt(item) OR self.et(item) THEN TRUE ELSE FALSE
  48.  
  49. -> ge() means 'Greater than/Equal to'.
  50.  
  51. EXPORT PROC ge(item:PTR TO sortobj) OF sortobj IS IF self.gt(item) OR self.et(item) THEN TRUE ELSE FALSE
  52.  
  53. -> ne() means 'Not Equal to'.
  54.  
  55. EXPORT PROC ne(item:PTR TO sortobj) OF sortobj IS IF self.et(item) THEN FALSE ELSE TRUE
  56.  
  57. -> cmp() means 'Compare', and will return 1, 0, or -1 depending upon whether
  58. -> the internal item is Less than, Equal to, or Greater than the incoming item.
  59. -> All the other comparative functions above depend upon this one, so don't
  60. -> mess it up <grin>.
  61.  
  62. EXPORT PROC cmp(item:PTR TO sortobj) OF sortobj IS EMPTY
  63.  
  64. -> set() merely sets a value.
  65.  
  66. EXPORT PROC set(in) OF sortobj IS EMPTY
  67.  
  68. -> write() creates a string of an item to print.
  69.  
  70. EXPORT PROC write() OF sortobj IS EMPTY
  71.  
  72. -> get() returns the item itself (if appropriate).
  73.  
  74. EXPORT PROC get() OF sortobj IS EMPTY
  75.  
  76. -> id() returns a unique id # for the type of object.
  77.  
  78. EXPORT PROC id() OF sortobj IS 0   -> the base class has '0' for its ID #.
  79.  
  80. -> end() is the de-allocator
  81.  
  82. PROC end() OF sortobj IS EMPTY
  83.